package com.db.williamchart.renderer.executor;

import com.db.williamchart.data.DataPoint;
import com.db.williamchart.data.Frame;

import java.util.ArrayList;
import java.util.List;

public class GetHorizontalBarBackgroundFrames {

    public List<Frame> invoke(
            Frame innerFrame,
            float spacingBetweenBars,
            List<DataPoint> data
    ) {

        float halfBarWidth =
                (innerFrame.getBottom() - innerFrame.getTop() - (data.size() + 1) * spacingBetweenBars) /
                        data.size() / 2;

        List<Frame> list = new ArrayList<>();
        for (DataPoint point : data) {
            Frame frame = new Frame(
                    innerFrame.getLeft(),
                    point.getScreenPositionY() - halfBarWidth,
                    innerFrame.getRight(),
                    point.getScreenPositionY() + halfBarWidth
            );
            list.add(frame);
        }
        return list;
    }

}
